import request from '@/utils/request'
import { ObjectType, ResponseDataPromise } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { Pagination } from '@/components/Records/types'

//首页融资列表
export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in/page2',
    method: 'post',
    data,
    params: pagination,
  })
//全量保存融资信息
export const createRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in',
    method: 'post',
    data,
  })

//融资主表删除
export const deleteRecordsRequest = (ids: string[]) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in`,
    method: 'delete',
    data: ids,
  })

export const editRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in',
    method: 'put',
    data,
  })

//根据id获取融资信息详情
export const getRecordRequest = (id: string) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in/${id}`,
    method: 'get',
  })


//获取表头信息
export const getRecordcolumns = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_CMS + '/dictItem/getFinancingHead',
    method: 'get',
  })

// 获取融资借款明细
export const fetchRecordsLoans = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in-loan/page',
    method: 'post',
    data,
    params: pagination,
  })

//保存、编辑、删除融资借款 
export const saveRecordLoans = (method: any, data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in-loan',
    method,
    data,
  })


//批量删除融资借款
export const deleteRecordsLoans = (ids: string[]) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in-loan`,
    method: 'delete',
    data: ids,
  })



// 获取融资还款明细
export const fetchRecordsRepay = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-financing-in-repay/page',
    method: 'post',
    data,
    params: pagination,
  })

// 保存、编辑、删除融资还款明细
export function RecordsRepay(data: any, method: any): Promise<any> {
  return request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in-repay`,
    method,
    data
  })
}

// 通过id查询历史信息数据
export function obtainHistory(data: any): Promise<any> {
  return request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in-repay/page/${data}`,
    method: 'get',
  })
}

//获取还款单位
export function getLoanUnit(data: any): Promise<any> {
  return request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in-loan/getLoanUnit`,
    method: 'post',
    data
  })
}




// export const lockRecordRequest = (id: string, dataLock: '0' | '1') =>
//   request({
//     url: proxy.CHECC_API_BASE_DATA + `/bd-fixed-section/${id}`,
//     method: 'post',
//     data: {
//       dataLock
//     },
//   })

// export const getRecordRequest = (id: string): ResponseDataPromise<ObjectType> =>
//   request({
//     url: proxy.CHECC_API_BASE_DATA + `/bd-financing-in-loan/${id}`,
//     method: 'get',
//   })

// export const exportRecordsRequest = (): ResponseDataPromise<ObjectType> =>
//   request({
//     url: proxy.CHECC_API_BASE_DATA + '/bd_traffic/export',
//     method: 'post',
//   })

// export const importRecordsRequest = (): ResponseDataPromise<ObjectType> =>
//   request({
//     url: proxy.CHECC_API_BASE_DATA + '/bd_traffic/import',
//     method: 'post',
//   })

